package com.itheima.info.manager.service;

import com.itheima.info.manager.dao.BaseStudentDao;
import com.itheima.info.manager.dao.StudentDao;
import com.itheima.info.manager.domain.Person;
import com.itheima.info.manager.domain.Student;
import com.itheima.info.manager.factroy.SystemFactory;

import java.util.ArrayList;

public class StudentService {
    BaseStudentDao studentDao = SystemFactory.getStudentDao();

    //判断学号是否存在
    public  boolean isExits(String id) {
        ArrayList<Student> list;
        list = studentDao.findAllStudent();
        Student student = new Student();
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            student = list.get(i);
            if (student != null && student.getId().equals(id)){
                flag = true;
                break;
            }
        }
        return flag;
    }
    //添加学生
    public void addStudent(Student student) {
        studentDao.addStudent(student);
    }
    //查看学生
    public ArrayList findAllStudent() {
        ArrayList<Student> allStudent = studentDao.findAllStudent();
        if (allStudent == null){
            return null;
        }else {
            return allStudent;
        }
    }
    //删除学生
    public void deleteStudentById(String id) {
        studentDao.deleteStudent(id);
    }
    //修改学生
    public void updateStudent(String id, Student student) {
        studentDao.updateStudent(id,student);
    }
}
